# encoding=utf8
import arcpy
import csv
import sys
reload(sys)
sys.setdefaultencoding( "utf-8" )

# envs settings
arcpy.env.workplace=u"E:/本机更新/MS_Thesis/data/wuhan/wuhan_temp.gdb/"
mxd = arcpy.mapping.MapDocument(u'E:/本机更新/MS_Thesis/data/wuhan/wuhan.mxd')
dflist=arcpy.mapping.ListDataFrames(mxd)

# read settings
colname = True

# read inputs
csv_reader = csv.reader(open(u"E:/2code/gitee/Python_Usingarcpy/temp/ms_thesis_wuhan_datamagement/select_features_copy.csv"))

table=[]
for row in csv_reader:
    table.append(row)

if colname:
    tablenames=table.pop(0)
    print tablenames
    print table
else:
    print table

# tools settings
lyrname=u"BUCA"
input_features=arcpy.mapping.ListLayers(mxd,lyrname,dflist[0])
relativepath=u"/BUCA_5工业/"

for i in range(len(table)):
    sql_clause=tablenames[0] + " = '" +table[i][0]+"'"
    out_features=arcpy.env.workplace+relativepath+table[i][1]
    # tools
    arcpy.SelectLayerByAttribute_management(in_layer_or_view=input_features[0], selection_type="NEW_SELECTION", where_clause=sql_clause)
    arcpy.CopyFeatures_management(in_features=input_features[0], out_feature_class=out_features, config_keyword="", spatial_grid_1="0", spatial_grid_2="0", spatial_grid_3="0")

print("done!")